SPB Git
761 B · 9 lines typescript
1import { headers } from "next/headers";2import { requireUser, jsonError, HttpError } from "@/lib/auth/guard";3import { clientIp } from "@/lib/auth/session";4import { actionSchema, toolAction, getToolRecord } from "@/lib/admin/tools";5export async function POST(req: Request, { params }: { params: Promise<{ id: string }> }) {6  try { const s = await requireUser(req); const r = await getToolRecord((await params).id); if (!r) throw new HttpError(404, "Not found"); await toolAction(r.id, actionSchema.parse(await req.json()), s, clientIp(await headers())); return Response.json({ ok: true }); }7  catch (e) { if (e instanceof Error && !(e as any).status && !("issues" in e)) return Response.json({ error: e.message }, { status: 400 }); return jsonError(e); }8}9
Files · main
Menu

Theme